package com.ruoyi.web.controller.record;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysRecord;
import com.ruoyi.system.service.ISysRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 采集记录表Controller
 * 
 * @author fhs
 * @date 2020-12-11
 */
@RestController
@RequestMapping("/system/record")
public class SysRecordController extends BaseController
{
    @Autowired
    private ISysRecordService sysRecordService;

    /**
     * 查询采集记录表列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysRecord sysRecord)
    {
        startPage();
        List<SysRecord> list = sysRecordService.selectSysRecordList(sysRecord);
        return getDataTable(list);
    }

    /**
     * 导出采集记录表列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "采集记录表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysRecord sysRecord)
    {
        List<SysRecord> list = sysRecordService.selectSysRecordList(sysRecord);
        ExcelUtil<SysRecord> util = new ExcelUtil<SysRecord>(SysRecord.class);
        return util.exportExcel(list, "record");
    }

    /**
     * 获取采集记录表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(sysRecordService.selectSysRecordById(id));
    }

    /**
     * 新增采集记录表
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "采集记录表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysRecord sysRecord)
    {
        return toAjax(sysRecordService.insertSysRecord(sysRecord));
    }

    /**
     * 修改采集记录表
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "采集记录表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysRecord sysRecord)
    {
        return toAjax(sysRecordService.updateSysRecord(sysRecord));
    }

    /**
     * 删除采集记录表
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "采集记录表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sysRecordService.deleteSysRecordByIds(ids));
    }
}
